package org.openkoala.koala.popup.javaclass.crud;

import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.openkoala.koala.deploy.curd.module.ui.UIWidget;
import org.openkoala.koala.deploy.curd.module.ui.view.DateView;
import org.openkoala.koala.deploy.curd.module.ui.view.HiddenView;
import org.openkoala.koala.deploy.curd.module.ui.view.QueryDropView;
import org.openkoala.koala.deploy.curd.module.ui.view.ReadOnlyView;
import org.openkoala.koala.deploy.curd.module.ui.view.RelativeReadOnlyView;
import org.openkoala.koala.deploy.curd.module.ui.view.StaticDropView;
import org.openkoala.koala.deploy.curd.module.ui.view.TextAreaView;
import org.openkoala.koala.deploy.curd.module.ui.view.TextView;

public class FieldTableLabelProvider extends LabelProvider implements ITableLabelProvider {

    @Override
    public Image getColumnImage(Object element, int columnIndex) {
        return null;
    }

    @Override
    public String getColumnText(Object element, int columnIndex) {
        UIWidget widget = (UIWidget) element;
        
        switch (columnIndex) {
        case 0:
        	if (widget instanceof RelativeReadOnlyView) {
        		return ((RelativeReadOnlyView) widget).getRelative();
        	}
            return widget.getExpress();
        case 1:
            return widget.getName();
        case 2:
        	if (widget instanceof TextView || widget instanceof TextAreaView || widget instanceof DateView || widget instanceof StaticDropView || 
        			widget instanceof QueryDropView || widget instanceof HiddenView) {
        		return CrudUtils.getEditTypeNameByUIWiget(widget);
        	}
        	
        	if (widget instanceof ReadOnlyView || widget instanceof RelativeReadOnlyView) {
        		return CrudUtils.getAssociationPropertyNameByUIWiget(widget);
        	}
        default:
            return "unknow" + columnIndex;
        }
    }
    
}
